package com.linln.modules.system.repository;

import java.util.List;

import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.linln.common.constant.StatusConst;
import com.linln.modules.system.domain.Area;
import com.linln.modules.system.domain.Menu;
import com.linln.modules.system.domain.User;

/**
 * @author 小懒虫
 * @date 2018/12/02
 */
public interface AreaRepository extends JpaRepository<Area, Long> {

  
    public Area findByCode(String code);
    public List<Area> findByCodeIn(List<String> code);

    public Area findByName(String name);
     
    
    /**
     * 根据父级菜单ID获取本级全部菜单
     * @param sort 排序对象
     * @param pid 父菜单ID
     * @param notId 需要排除的菜单ID
     * @return 菜单列表
     */
    public List<Area> findByPidAndIdNot(Sort sort, long pid, long notId);
    
    
    /**
     * 根据父级菜单ID获取本级全部菜单
     * @param sort 排序对象
     * @param pid 父菜单ID
     * @param notId 需要排除的菜单ID
     * @return 菜单列表
     */
    @Query("select m from Area m where m.pid = ?1")
    public List<Area> findByPid(Sort sort, long pid);
    
    /**
     * 获取排序最大值
     * @param pid 父菜单ID
     * @return 最大值
     */
    @Query("select max(sort) from Area m where m.pid = ?1 and m.status <> " + StatusConst.DELETE)
    public Integer findSortMax(long pid);
    
    @Query("SELECT u FROM Area u WHERE u.name LIKE CONCAT('%',:name,'%')")
    public List<Area> findByLikeName(String name);
    
    
    @Query("SELECT u FROM Area u WHERE u.code like '____00'")
    public List<Area> getCityList();
    

    


}

